package com.vfa.fishing.animal;

import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import android.os.Parcel;

import com.vfa.fishing.GameActivity;
import com.vfa.fishing.MenuActivity;
import com.vfa.fishing.common.AbstractObject;
import com.vfa.fishing.common.Constant;

public class Person extends AbstractObject {
        public boolean Visible;
        public boolean isFishing;//bat len khi nguoi chay den vi tri buong cau,hoac buong cau
        public float  speed = 15;
        public int xFishing;// toa do X buong cau
        public int yFishing;// toa do X buong cau
        public int direction;
        public int sideAppear;
        public int blood;// mau nguoi cau ca
        public int strength;// suc khoe nguoi cau ca,neu co suc khoe lon thi co the cau duoc ca lon
        public int lengthsOfline;// neu day cau dai thi co the cau ca o duoi tang sau
        public int amountOfMoney;
        public boolean isCatchOk;// khi cau trung duoc 1 thu gi do,bat co nay len
        public boolean isMoving;//khi con thuyen dang di chuyen
        public boolean isTimeDelayInFishing;
        private int iTimer;

        // Constructor
        public Person(int x,int y,TiledTextureRegion pTextureRegion,int sideApp){
            super(x,y,pTextureRegion,sideApp);
            sideAppear = sideApp;// huong xuat hien cua con ca
            if(sideAppear == Constant.LEFTSIDE){
                direction = Constant.RIGHT;
            }
            else if(sideAppear == Constant.RIGHTSIDE){
                direction = Constant.LEFT;
            }
            blood = 100;
            strength = 10;
            lengthsOfline = 200; //200
            this.kindOfObject = Constant.PERSON;
            amountOfMoney = 0;
            isCatchOk = false;
            isTimeDelayInFishing = false;
        }

        public Person(int Xposition, int Yposition, TiledTextureRegion pTextureRegion, int direction, int sideAppear, int blood, int strength, int lengthsOfline
                , int amoutnOFMoney) {//, boolean isMoving, boolean isTimeDelayInFishing) {
            super(Xposition, Yposition, pTextureRegion);
            this.direction = direction;
            this.sideAppear = sideAppear;
            this.blood = blood;
            this.strength = strength;
            this.lengthsOfline = lengthsOfline;
            this.amountOfMoney = amoutnOFMoney;
//            this.isMoving = isMoving;
//            this.isTimeDelayInFishing = isTimeDelayInFishing;
            this.kindOfObject = Constant.PERSON;
            isCatchOk = false;
            isTimeDelayInFishing = false;

        }
        public void update(int target)
        {
            int X= (int) (this.getX());
//        	Log.d("UpdateBoat", "target: "+target);
//        	Log.d("UpdateBoat", "width: "+this.getWidth());
            if(target - X > 0 && X < (MenuActivity.CAMERA_WIDTH +(this.getWidth()/4))) {
                X +=speed;
                direction = Constant.RIGHT;
            }
            else {
                X -= speed;// van toc la 2
                direction = Constant.LEFT;
            }

            if(direction == Constant.RIGHT) {
                if(X < (target - (this.getWidth()/2))){
                    this.setPosition(X, this.getY());
                    isMoving = true;
                }
                else {
                    // den day buong cau,bat co len
//                    isFishing = true;
                    isMoving = false;
                }
            }
            else if(direction == Constant.LEFT) {
                if(X >(target-(this.getWidth()/2))) {
                    this.setPosition(X, this.getY());
                    isMoving = true;
                }
                else {
                    // den day buong cau,bat co len
//                    isFishing = true;
                    isMoving = false;
                }
            }
            //cap nhat cac thong so tai day
            update();
        }

        @Override
        public void Eat() {
            // TODO Auto-generated method stub

        }

        @Override
        public void update() {
            iTimer = GameActivity.TIMER;
            iTimer++;
            if(iTimer > 1000000)
                iTimer = 0;
//            if(isCatchOk && iTimer%5)
            // TODO Auto-generated method stub
            // cap nhat blood,streng,amountOfMoney,lengthOfline trong nay
            //update máu
            //update streng
            //update dây câu
            if(isCatchOk){

            }

        }

        /**check xem nguoi buong cau duoc chua.khi tourch vao man hinh,nguoi buong cau se  buong cau ngay tai cho*/
        private boolean checkFishing(AbstractObject object){
            if(Constant.checkCollision(xFishing, yFishing, (int)object.getX(),(int)object.getY(), (int)(object.getX()+object.getWidth()), (int)(object.getY()+object.getHeight()))){
                isCatchOk = true;// bat co len neu cau trung
                if(object.kindOfObject == Constant.FISH){
                    // xu ly truong hop cau trung ca
                    Fish fish = (Fish)object;
                    if (strength < fish.weight) {
                        isTimeDelayInFishing = true;
                    }
                    else if(strength >= fish.weight) {
                        isTimeDelayInFishing = true;
                    }
                }
                else if(object.kindOfObject == Constant.ITEM){
                    //item
                }
                else if(object.kindOfObject == Constant.SHELLS){
                    // oc so
                }
                else if(object.kindOfObject == Constant.CRAB){
                    // cua
                }
                else if(object.kindOfObject == Constant.SHRIMP){
                    //tom
                }
                else if(object.kindOfObject == Constant.CUTLE){
                    // muc
                }
                return true;
            }
            return false;
        }

        public void setFishingFlag(){
            isFishing = true;
        }

        @Override
        public void resetDirection() {
            // TODO Auto-generated method stub

        }

        @Override
        public int getCoin() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int describeContents() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            // TODO Auto-generated method stub

        }
}
